/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package s.f.login;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Froy
 */
public class FiltroLoginAdmin implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpSession sesion = req.getSession(true);

        if(sesion.getAttribute("usuario") != null){
            chain.doFilter(request, response);
        } else{
            HttpServletResponse resp = (HttpServletResponse) response;
            resp.sendRedirect("/empleados/login.jsp");
        }
    }

    @Override
    public void destroy() {
    }
}
